<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBClientAction_member extends KBClientAction_common
{

	function &execute($controller, $manager) {
		
		// check if registration is not required
		if(!$manager->use_registration || !$manager->is_registered) {
			$controller->go();
		}	
		
		
		$view = &$controller->getView('register');
		$view->update = true;
		
		$manager_1 = new MemberModel;
		
		if(isset($this->rp->submit)) {
			
			$errors = $view->validate($this->rp->vars, $manager, $manager_1);
			
			if($errors) {
				$this->rp->stripVars(true);
				$view->setErrors($errors);
				$view->setFormData($this->rp->vars);
			
			} else {
				
				$this->rp->stripVars();
				$view->obj->set($this->rp->vars);
				$view->obj->setPassword($this->rp->not_change_pass); // mean not insert in db if not_change_pass = 1
				
				$manager_1->save($view->obj);
			
				$auth = new AuthPriv;
				if(!$this->rp->vars['remember']) { $auth->removeCookie(); }
				
				$controller->go('success_go', false, false, 'updated');
			}
		
		} else {
			
			$data = $manager_1->getById($manager->user_id);
			$view->setFormData($data);
		}
		
		return $view;
	}
	
}
?>